package com.example.keshe.controller;
import com.alibaba.fastjson.JSON;
import com.example.keshe.Service.CarDataService;
import com.example.keshe.entity.CarData;
import com.example.keshe.mq.MIdObject;
import com.example.keshe.mq.PidObject;
import com.example.keshe.mq.Signal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;




import java.util.List;

@Controller
public class CarDataController {

    @Autowired
    CarDataService carDataService;

    @Autowired
    CosumerController cosumerController;

    @Autowired
    MIdObject mIdObject;

    @Autowired
    PidObject pidObject;

    @Autowired
    ProducerController producerController;

    @Autowired
    Signal signal;

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @RequestMapping("/selectList")
    public String selectList(Model model) {
        List<CarData> list = carDataService.listCarDataEntity();
        model.addAttribute("carDataList",list);

        return "carData1";
    }

    @GetMapping("/deleteAll")
    public String deleteAll(){
        carDataService.deleteAll();
        return "success";
    }


    @RequestMapping("/huabu1")
    public String getHuaBu(Model model){
        return "draw";
    }

    @RequestMapping("/picture1")
    public String getPicture1(Model model){
        return "picture1";
    }


    @RequestMapping("/picture2")
    public String getPicture2(Model model){
        return "picture2";
    }




    @RequestMapping("/PID")
    public String temp(){
        return "pid";
    }



   @RequestMapping ("/pid")
    public String pid(String p,String i,String d){
        pidObject.setP(p);
        pidObject.setI(i);
        pidObject.setD(d);
       String s = JSON.toJSONString(pidObject);
       producerController.send("my-topic5",s);
       System.out.println(s);
        return "success";
    }



    @RequestMapping ("/stop_start")
    public String stopStart(){
        return "stopStart";
    }

    @RequestMapping("/start")
    public String start(){
        signal.setSign("start");
        String s = JSON.toJSONString(signal);
        System.out.println(s);
        producerController.send("my-topic6",s);
        System.out.println(s);
        return "success";
    }


    @RequestMapping("/stop")
    public String stop(){
        signal.setSign("stop");
        String s = JSON.toJSONString(signal);
        producerController.send("my-topic6",s);
        System.out.println(s);
        return "success";
    }





}
